#include <stdio.h>
#include <stdlib.h>
#include "menu.h"

void log_selection(char option);

int main() {
    char choice;
    FILE *log = fopen("log.txt", "a");
    if (log == NULL) {
        printf("无法打开log.txt文件\n");
        return 1;
    }

    do {
        printf("------------------\n");
        printf("C\t交互菜单\n");
        printf("------------------\n");
        printf("A: 查看CPU硬件信息\n");
        printf("B: 查看进程运行信息\n");
        printf("C: 查看内存硬件信息、内存使用信息\n");
        printf("D: 查看存储设备硬件信息、存储设备使用信息\n");
        printf("E: 退出\n");
        printf("------------------\n");
        printf("请选择一个选项: ");
        scanf(" %c", &choice);

        log_selection(choice);
        switch (choice) {
            case 'A':
                show_cpu_info();
                break;
            case 'B':
                show_process_info();
                break;
            case 'C':
                show_memory_info();
                break;
            case 'D':
                show_storage_info();
                break;
            case 'E':
                printf("退出程序\n");
                break;
            default:
                printf("无效选项，请重新选择\n");
        }
    } while (choice != 'E');

    fclose(log);
    return 0;
}

void log_selection(char option) {
    FILE *log = fopen("log.txt", "a");
    if (log == NULL) {
        printf("无法打开log.txt文件 \n");
        return;
    }
    fprintf(log, "用户选择了选项: %c\n", option);
    fclose(log);
}